ostbuild: More work on deploy commands
authorColin Walters <walters@verbum.org>
Wed, 2 May 2012 18:49:32 +0000 (14:49 -0400)
committerColin Walters <walters@verbum.org>
Fri, 4 May 2012 20:16:16 +0000 (16:16 -0400)
Makefile-ostbuild.am
src/ostbuild/pyostbuild/builtin_build_components.py
src/ostbuild/pyostbuild/builtin_deploy_qemu.py [new file with mode: 0755]
src/ostbuild/pyostbuild/builtin_deploy_root.py [new file with mode: 0755]
src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py [new file with mode: 0755]
src/ostbuild/pyostbuild/builtins.py
src/ostbuild/pyostbuild/main.py
src/ostbuild/pyostbuild/privileged_subproc.py [new file with mode: 0755]

index b561a28d73e2fbd9886b3710b9a075f13d6f63f1..0c87e65c66d6f730466cad1dd3e47e946c8a741c 100644 (file)
@@ -29,6 +29,7 @@ pyostbuild_PYTHON =                                   \
        src/ostbuild/pyostbuild/builtin_compose.py      \
        src/ostbuild/pyostbuild/builtin_chroot_compile_one.py   \
        src/ostbuild/pyostbuild/builtin_compile_one.py  \
+       src/ostbuild/pyostbuild/builtin_deploy_root.py  \
        src/ostbuild/pyostbuild/builtin_pull_components.py      \
        src/ostbuild/pyostbuild/builtin_git_mirror.py   \
        src/ostbuild/pyostbuild/builtin_prefix.py       \
@@ -48,6 +49,7 @@ pyostbuild_PYTHON =                                   \
        src/ostbuild/pyostbuild/odict.py                \
        src/ostbuild/pyostbuild/ostbuildlog.py          \
        src/ostbuild/pyostbuild/ostbuildrc.py           \
+       src/ostbuild/pyostbuild/privileged_subproc.py   \
        src/ostbuild/pyostbuild/warningfilter.py        \
        src/ostbuild/pyostbuild/subprocess_helpers.py   \
        src/ostbuild/pyostbuild/vcs.py                  \
index 7ae787c22e07de286a07b19f97737530d8976101..5983dea05ddcb3c37417ac861bbff124fc1ae9c6 100755 (executable)
@@ -101,9 +101,14 @@ class OstbuildBuildComponents(builtins.Builtin):
                     return False
             else:
                 current_vcs_version = component['revision']
-                previous_vcs_version = json.loads(previous_metadata_text)['revision']
-                if current_vcs_version != previous_vcs_version:
+                previous_metadata = json.loads(previous_metadata_text)
+                previous_vcs_version = previous_metadata['revision']
+                if current_vcs_version == previous_vcs_version:
                     log("Metadata differs; VCS version unchanged")
+                    for k,v in meta_copy.iteritems():
+                        previous_v = previous_metadata.get(k)
+                        if v != previous_v:
+                            log("Key %r differs: old: %r new: %r" % (k, previous_v, v))
                 else:
                     log("Metadata differs; note vcs version is now '%s', was '%s'" % (current_vcs_version, previous_vcs_version))
         else:
diff --git a/src/ostbuild/pyostbuild/builtin_deploy_qemu.py b/src/ostbuild/pyostbuild/builtin_deploy_qemu.py
new file mode 100755 (executable)
index 0000000..5afea83
--- /dev/null
@@ -0,0 +1,58 @@
+# Copyright (C) 2012 Colin Walters <walters@verbum.org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import os,sys,subprocess,tempfile,re,shutil
+import argparse
+import time
+import urlparse
+import json
+from StringIO import StringIO
+
+from . import builtins
+from .ostbuildlog import log, fatal
+from . import ostbuildrc
+from . import privileged_subproc
+
+class OstbuildDeployQemu(builtins.Builtin):
+    name = "deploy-qemu"
+    short_description = "Extract data from shadow repository to qemu"
+
+    def __init__(self):
+        builtins.Builtin.__init__(self)
+
+    def execute(self, argv):
+        parser = argparse.ArgumentParser(description=self.short_description)
+        parser.add_argument('--prefix')
+        parser.add_argument('--bin-snapshot')
+
+        args = parser.parse_args(argv)
+        self.args = args
+        
+        self.parse_config()
+        self.parse_bin_snapshot(args.prefix, args.bin_snapshot)
+        
+        target_names = []
+        for target in self.bin_snapshot['targets']:
+            target_names.append(target['name'])
+
+        helper = privileged_subproc.PrivilegedSubprocess()
+        sys_repo = os.path.join(self.ostree_dir, 'repo')
+        shadow_path = os.path.join(self.workdir, 'shadow-repo')
+        helper.spawn_sync(['ostree', '--repo=' + sys_repo,
+                           'pull-local', shadow_path])
+        
+builtins.register(OstbuildDeployRoot)
diff --git a/src/ostbuild/pyostbuild/builtin_deploy_root.py b/src/ostbuild/pyostbuild/builtin_deploy_root.py
new file mode 100755 (executable)
index 0000000..13f9f17
--- /dev/null
@@ -0,0 +1,58 @@
+# Copyright (C) 2012 Colin Walters <walters@verbum.org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import os,sys,subprocess,tempfile,re,shutil
+import argparse
+import time
+import urlparse
+import json
+from StringIO import StringIO
+
+from . import builtins
+from .ostbuildlog import log, fatal
+from . import ostbuildrc
+from . import privileged_subproc
+
+class OstbuildDeployRoot(builtins.Builtin):
+    name = "deploy-root"
+    short_description = "Extract data from shadow repository to system repository"
+
+    def __init__(self):
+        builtins.Builtin.__init__(self)
+
+    def execute(self, argv):
+        parser = argparse.ArgumentParser(description=self.short_description)
+        parser.add_argument('--prefix')
+        parser.add_argument('--bin-snapshot')
+
+        args = parser.parse_args(argv)
+        self.args = args
+        
+        self.parse_config()
+        self.parse_bin_snapshot(args.prefix, args.bin_snapshot)
+        
+        target_names = []
+        for target in self.bin_snapshot['targets']:
+            target_names.append(target['name'])
+
+        helper = privileged_subproc.PrivilegedSubprocess()
+        sys_repo = os.path.join(self.ostree_dir, 'repo')
+        shadow_path = os.path.join(self.workdir, 'shadow-repo')
+        helper.spawn_sync(['ostree', '--repo=' + sys_repo,
+                           'pull-local', shadow_path])
+        
+builtins.register(OstbuildDeployRoot)
diff --git a/src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py b/src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py
new file mode 100755 (executable)
index 0000000..16b6bbb
--- /dev/null
@@ -0,0 +1,56 @@
+# Copyright (C) 2012 Colin Walters <walters@verbum.org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import os,sys,subprocess,tempfile,re,shutil
+import argparse
+import time
+import urlparse
+import json
+from StringIO import StringIO
+
+from . import builtins
+from .ostbuildlog import log, fatal
+from . import ostbuildrc
+from . import privileged_subproc
+
+class OstbuildPrivhelperDeployQemu(builtins.Builtin):
+    name = "privhelper-deploy-qemu"
+    short_description = "Helper for deploy-qemu"
+
+    def __init__(self):
+        builtins.Builtin.__init__(self)
+
+    def execute(self, argv):
+        parser = argparse.ArgumentParser(description=self.short_description)
+
+        args = parser.parse_args(argv)
+        self.args = args
+        
+        self.parse_config()
+        self.parse_bin_snapshot(args.prefix, args.bin_snapshot)
+        
+        target_names = []
+        for target in self.bin_snapshot['targets']:
+            target_names.append(target['name'])
+
+        helper = privileged_subproc.PrivilegedSubprocess()
+        sys_repo = os.path.join(self.ostree_dir, 'repo')
+        shadow_path = os.path.join(self.workdir, 'shadow-repo')
+        helper.spawn_sync(['ostree', '--repo=' + sys_repo,
+                           'pull-local', shadow_path])
+        
+builtins.register(OstbuildDeployRoot)
index 211a14c2bede9ef26b8b6e82b10bf341cc75094b..a167e9b014ebe559b849de5854a009ce551f1677 100755 (executable)
@@ -42,12 +42,12 @@ class Builtin(object):
         self.snapshot = None
         self.bin_snapshot = None
         self.repo = None
-        self.ostree_dir = self._find_ostree_dir()
+        self.ostree_dir = self.find_ostree_dir()
         (self.active_branch, self.active_branch_checksum) = self._find_active_branch()
         self._src_snapshots = None
         self._bin_snapshots = None
 
-    def _find_ostree_dir(self):
+    def find_ostree_dir(self):
         for path in ['/ostree', '/sysroot/ostree']:
             if os.path.isdir(path):
                 return path
@@ -180,9 +180,12 @@ class Builtin(object):
             else:
                 fatal("No repository configured, and shadow-repo not found.  Use \"ostbuild shadow-repo-init\" to make one")
 
-    def parse_snapshot(self, prefix, path):
+    def parse_prefix(self, prefix):
         if prefix is not None:
             self.prefix = prefix
+
+    def parse_snapshot(self, prefix, path):
+        self.parse_prefix(prefix)
         self._init_repo()
         if path is None:
             latest_path = self.get_src_snapshot_db().get_latest_path()
@@ -197,8 +200,7 @@ class Builtin(object):
             fatal("Unhandled 00ostree-src-snapshot-version \"%d\", expected 0" % (src_ver, ))
 
     def parse_bin_snapshot(self, prefix, path):
-        if prefix is not None:
-            self.prefix = prefix
+        self.parse_prefix(prefix)
         self._init_repo()
         if path is None:
             latest_path = self.get_bin_snapshot_db().get_latest_path()
index 488a563124b6392977f75c486174af610770a24f..35d150ad7b2805fde454183157246aed6620b882 100755 (executable)
@@ -29,6 +29,7 @@ from . import builtin_checkout
 from . import builtin_chroot_compile_one
 from . import builtin_compose
 from . import builtin_compile_one
+from . import builtin_deploy_root
 from . import builtin_git_mirror
 from . import builtin_pull_components
 from . import builtin_prefix
diff --git a/src/ostbuild/pyostbuild/privileged_subproc.py b/src/ostbuild/pyostbuild/privileged_subproc.py
new file mode 100755 (executable)
index 0000000..982984b
--- /dev/null
@@ -0,0 +1,39 @@
+# Copyright (C) 2012 Colin Walters <walters@verbum.org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import os,sys,subprocess
+
+from .ostbuildlog import log, fatal
+from . import ostbuildrc
+
+class PrivilegedSubprocess(object):
+
+    def spawn_sync(self, argv):
+        helper = ostbuildrc.get_key('privileged_exec', default='pkexec')
+
+        handlers = {'pkexec': self._pkexec_spawn_sync}
+
+        handler = handlers.get(helper)
+        if handler is None:
+            fatal("Unrecognized privileged_exec; valid values=%r" % (handlers.keys(),))
+        else:
+            handler(argv)
+
+    def _pkexec_spawn_sync(self, argv):
+        pkexec_argv = ['pkexec'] + argv
+        log("Running: %s" % (subprocess.list2cmdline(pkexec_argv), ))
+        subprocess.check_call(pkexec_argv)